package day01

object CharDemo {
  def main(args: Array[String]): Unit = {
    // 字符类型
    val c1 = 'a'
    println(c1)
    val typeInfo = checkType(c1)
    // Character
    println(typeInfo)

    val c2:Char = '9'
    println(c2)

    // 控制字符
    // 制表符
    val c3 = '\t'
    // 操作符
    val c4 = '\n'
    println("abc" + c3 + "def")
    println("abc" + c4 + "def")

    println("=================================>")
    val c5 = '\\'
    val c6 = '\"'
    print("abc" + c5 + "def")
    print("abc" + c6 + "def")

    println("=================================>")
    // 字符变量底层保存 ASCII 码
    val i1:Int = c1
    println("i1： " + i1) // 97

    val i2:Int = c2
    println("i2: " + i2)  // 57

    val c7:Char = (i1 + 1).toChar
    println(c7)  // b

    val c8:Char = (i1 - 1).toChar
    println(c8)  // .

  }


  def checkType(x: Any): String = x match {
    case _: String => "String"
    case _: Int => "Int"
    case _: Double => "Double"
    case _: Float => "Float"
    case _: Char => "Char"
    case _: Boolean => "Boolean"
    case _: List[_] => "List"
    case _ => "Unknown"
  }

}
